package littlewhisker.utils {

	import flash.display.Sprite;
	/**
	 * @author Philip
	 */
	public class VisualOrder {
		
		public static function bringToFront(target:Sprite, source:Sprite):void{
		
			source.setChildIndex(target,source.numChildren - 1);
		
		}
		
		public static function sendToBack(target:Sprite, source:Sprite):void{
			source.setChildIndex(target,0);
		}
		
		public static function swapDepths(target:Sprite, itemToSwapWith:Sprite, source:Sprite):void{
	
			var otherindex:uint = source.getChildIndex(itemToSwapWith);
			source.setChildIndex(itemToSwapWith, source.getChildIndex(target));
			source.setChildIndex(target, otherindex);
		}
		
		public static function putInFrontOf(target:Sprite, victim:Sprite, source:Sprite):void{
		
			var victimIndex:uint = source.getChildIndex(victim);
			source.setChildIndex(target, victimIndex+1);
		}
		
		public static function putBehind(target:Sprite, victim:Sprite, source:Sprite):void{
			
			var victimIndex:uint = source.getChildIndex(victim);
			source.setChildIndex(target, victimIndex);
		}
		
		public static function bringForward(target:Sprite, source:Sprite):void{
			
			var currentIndex:uint = source.getChildIndex(target);
			if(currentIndex<source.numChildren) source.setChildIndex(target, currentIndex+1);
		}
		
		public static function sendBackward(target:Sprite, source:Sprite):void{
			
			var currentIndex:uint = source.getChildIndex(target);
			if(currentIndex>0) source.setChildIndex(target, currentIndex-1);
		}
		
	}
}
